package indi.a709924470.scpwiki.RecycleViewThings;

import android.content.Context;
import android.content.Intent;
import android.os.Parcelable;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import org.w3c.dom.Text;

import java.io.Serializable;
import java.util.List;
import java.util.concurrent.ExecutionException;

import indi.a709924470.scpwiki.HolderType;
import indi.a709924470.scpwiki.MainPageActivity;
import indi.a709924470.scpwiki.ParseWikiPage;
import indi.a709924470.scpwiki.R;
import indi.a709924470.scpwiki.SubRVAct;
import indi.a709924470.scpwiki.beans.Constants;
import indi.a709924470.scpwiki.beans.TheBean;
import indi.a709924470.scpwiki.beans.WikiItems;
import indi.a709924470.scpwiki.beans.WikiSubItems;
import indi.a709924470.scpwiki.webView;

import static indi.a709924470.scpwiki.MainPageActivity.*;

/**
 * Created by Walter Ji on 2017/12/25.
 */

public class srcvwHolder extends RecyclerView.Adapter<srcvwHolder.RVHlder> {

    Context ctx;
    List<WikiSubItems> lws;
    int type;

    public srcvwHolder(List<WikiSubItems> lws, Context ctx,int type) {
        this.lws = lws;
        this.ctx = ctx;
        this.type = type;
    }

    @Override
    public RVHlder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new RVHlder(LayoutInflater.from(ctx).inflate(R.layout.sub_wiki_items, parent, false));
    }

    @Override
    public void onBindViewHolder(final RVHlder holder, final int position) {
        holder.tx.setText(lws.get(position).name);
        Log.d("srcview", "onClick: "+type);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                switch (type) {
                    case 0:
                        if (lws.get(position).url == null) return;
                        Log.d("srcview", "onClick: SUBRV Created!");
                        Intent i = new Intent(ctx, SubRVAct.class);
                        i.putExtra("Url", lws.get(position).url);
                        Constants.url = lws.get(position).url;
                        ctx.startActivity(i);
                        break;
                    case 1:
                        Log.d("srcview", "onClick: WebView Created!");
                        Intent i1 = new Intent(ctx,webView.class);
                        i1.putExtra("Url",lws.get(position).url);
                        ctx.startActivity(i1);
                        break;
                    default:
                        Log.d("srcview", "onClick: Nothing Happened.");
                        break;
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return lws.size();
    }

    class RVHlder extends RecyclerView.ViewHolder{
        TextView tx;
        public RVHlder (View iV){
            super(iV);
            tx = (TextView) iV.findViewById(R.id.subItem);
        }
    }
}
